home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
User's Choice Windows CD
/
User's Choice Windows CD (CMS Software)(1993).iso
/
windows4
/
plx17.zip
/
TEXTSTRM.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1992-06-14
|
3KB
|
125 lines
{TextStrm - Extensions to ObjectWindows Copyright (C) Doug Overmyer 7/1/91}
unit TextStrm;
{********************** Interface *************************}
interface
uses WinTypes, WinProcs, WinDos, Strings, WObjects,WFPlus;
type
PTextStream = ^TTextStream ;
TTextStream = object(TBufStream)
CharsToRead : LongInt;
CharsRead : LongInt;
ARecord :PChar;
constructor Init(FileName:PChar;Mode,Size:Word);
destructor Done;virtual;
function GetNext:PChar;virtual;
function WriteNext(szARecord:PChar):integer;virtual;
function WriteEOF:integer;virtual;
function IsEOF:Boolean;virtual;
function GetPctDone:Integer;
end;
{************************ Implementation ********************}
implementation
{************************ TTextStream **********************}
constructor TTextStream.Init(FileName:PChar; Mode,Size:Word);
begin
TBufStream.Init(FileName,Mode,Size);
CharsRead := 0;
CharsToRead := TBufStream.GetSize;
ARecord := MemAlloc(32000);
end;
destructor TTextStream.Done;
begin
TBufStream.Done;
FreeMem(ARecord,32000);
end;
{replace unwanted control chars with spaces 10/5/91}
function TTextStream.GetNext:PChar;
var
Blksize:Integer;
AChar:Char;
Indx : Integer;
IsEOR : Boolean;
begin
Indx := 0;
IsEOR := False;
ARecord[0] := #0;
while (CharsRead < CharsToRead) and (IsEOR = False) do
begin
TBufStream.Read(AChar,1);
Inc(CharsRead);
case AChar of
#13:
begin
ARecord[Indx] := #0;
IsEOR := True;
end;
#26:
begin
if Indx > 0 then
begin
ARecord[Indx] := #0;
IsEOR := True;
end;
end;
#10:
begin
end;
#9:
begin
ARecord[Indx] := AChar;
Inc(Indx);
end;
#0..#31:
begin
ARecord[Indx] := ' ';
Inc(Indx);
end;
else
begin
ARecord[Indx] := AChar;
inc(Indx);
end;
end;
end;
ARecord[Indx] := #0;
GetNext := ARecord;
end;
{This method not actually used due to performance loss - instead
TStream.Write is called directly}
function TTextStream.WriteNext(szARecord:PChar):Integer;
const
CRLF : Array[0..2] of Char = #13#10#0;
begin
TBufStream.Write(szARecord,
StrLen(szARecord));
TBufStream.Write(CRLF,2);
WriteNext := StrLen(szARecord);
end;
function TTextStream.WriteEOF:Integer;
const
EOF : Array[0..1] of Char = #26;
begin
TBufStream.Write(EOF,1);
WriteEOF := 1;
end;
function TTextStream.IsEOF:Boolean;
begin
IsEOF := False;
if CharsRead >= CharsToRead then
IsEOF := True;
end;
function TTextStream.GetPctDone:Integer;
begin
GetPctDone := CharsRead*100 div CharsToRead;
end;
end.